package com.example.modules.course.web;

import com.example.modules.course.model.TCourse;
import com.example.modules.course.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: Oliver
 * @Date: 2019/2/21 11:52
 * @Description:
 */

@Api(value = "/api/course", tags = "课程资源模块")
@RestController
@RequestMapping("/api/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @ApiOperation(value = "课程资源添加",notes = "添加课程资源")
    @PostMapping
    public TCourse addCourse(@RequestBody TCourse course) {
        return courseService.addCourse(course);
    }

    @ApiOperation(value = "课程资源修改",notes = "添加课程修改")
    @PutMapping("{id}")
    public void updateCourse(@PathVariable("id") TCourse old, @RequestBody TCourse self) {
        courseService.updateCourse(old, self);
    }

    @ApiOperation(value = "课程资源分页查询",notes = "课程资源分页查询")
    @GetMapping
    public Page<TCourse> selectCourses(TCourse course, Pageable pageable) {
        return courseService.selectPage(course, pageable);
    }

    @ApiOperation(value = "课程资源根据id查询",notes = "课程资源根据id查询")
    @GetMapping("{id}")
    public TCourse selectById(@PathVariable("id") TCourse course) {
        return course;
    }

    @ApiOperation(value = "课程资源根据id删除",notes = "课程资源根据id删除")
    @DeleteMapping
    public void deleteCourse(@RequestBody List<Long> ids) {
        courseService.deleteCourse(ids);
    }

}
